package com.xindacloud.sms.console.system.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xindacloud.sms.console.constant.SessionKeys;
import com.xindacloud.sms.console.result.Result;
import com.xindacloud.sms.console.system.dto.SmsAccountTransationDTO;
import com.xindacloud.sms.console.system.entity.SmsAccountTransation;
import com.xindacloud.sms.console.system.entity.SmsUser;
import com.xindacloud.sms.console.system.service.ISmsAccountTransationService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author czc
 * @since 2019-11-28
 */
@Api(tags = {"账号余额模块"})
@RestController
@RequestMapping("/api/v1/sms-account-transation")
public class SmsAccountTransationController {
	
	@Autowired
	private ISmsAccountTransationService smsAccountTransationService;

	@ApiOperation(value = "查询交易记录", response = SmsAccountTransation.class)
	@PostMapping(value = "/getAccountBalance")
	public Result getAccountBalance(@RequestBody SmsAccountTransationDTO smsAccountTransationDTO, HttpServletRequest request) {
		 HttpSession session = request.getSession();
	     SmsUser user = (SmsUser) session.getAttribute(SessionKeys.ACCOUNT);
	     smsAccountTransationDTO.setOperatorId(user.getUserId());
	    /* smsAccountTransationDTO.setOperatorId(1);*/
		return smsAccountTransationService.getAccountBalance(smsAccountTransationDTO);
	}

	@ApiOperation(value = "充值或扣费", response = SmsAccountTransation.class)
	@PostMapping(value = "/addOrCostAccountBalance")
	public Result addOrCostAccountBalance(@RequestBody SmsAccountTransationDTO smsAccountTransationDTO, HttpServletRequest request) {
		HttpSession session = request.getSession();
	    SmsUser user = (SmsUser) session.getAttribute(SessionKeys.ACCOUNT);
	    smsAccountTransationDTO.setOperatorId(user.getUserId());
		return smsAccountTransationService.addOrCostAccountBalance(smsAccountTransationDTO);
	}

}
